package middlewares

import (
	"goGin/tools"

	"github.com/gin-gonic/gin"
)

type tokendata struct {
	Data   interface{}
	Token  interface{}
	Istrue bool
}

func Token() gin.HandlerFunc {
	return func(c *gin.Context) {
		data, token := tools.Gettoken(c)
		if token != nil {
			d := tokendata{
				Data:   data,
				Token:  token,
				Istrue: true,
			}
			c.Set("tokendata", d)
		} else {
			d := tokendata{
				Data:   data,
				Istrue: false,
			}
			c.Set("tokendata", d)
		}
		c.Next()
	}
}
